#ifndef GELEMENT_H
#define GELEMENT_H

#include <QtGui/QGraphicsItemGroup>
#include <QtSvg/QGraphicsSvgItem>
#include <QtCore/QList>
#include "../Token.h"
class DElement;
class QGraphicsTextItem;
class QDomElement;
class QSvgRenderer;
class Link;


/************************************************************************
**   Visitor Pattern: visitor (Variant) 
**   subclasses of GElement are visitors of subclasses of DElement                                                                   
*************************************************************************/

/************************************************************************
**  Note: QGraphicsItem term: Parent & Group
**        Parent: used to manage objects and calculate the position.
**        Group: used to show all objects in it as one QGraphisItem. 
************************************************************************/

//notice that: subclasses of GElement constructor should contain
//             a pointer to subclasses of DElement
//derived from QObject want to get signal and slots mechanism
class GElement : public QGraphicsItemGroup
{
	friend class TokensModel;
public:
	GElement(DElement* aDElement, QGraphicsItem *parent=0);
	~GElement() { qDeleteAll(mTokens); }

	// Enable the use of qgraphicsitem_cast with this item.
	enum { Type = UserType + 1 };
	int type() const { return Type; }

	DElement* description() const { return keyDElement; }
	//for view and persistence
	QString elementName();
	void setElementName(const QString & name);
	QString kind();
	QString className();

	void setTokens(const QList<Token*>& tokenList);
	const QList<Token*>& tokens() const;
	void addToken(Token* newToken);
	void deleteToken(int index);

	QPointF svgCenter();

	virtual void removeLink(Link *arrow) =0;
	virtual QList<Link*> allLinks() const =0;

protected:
	DElement* keyDElement;
	QGraphicsSvgItem centerSvg;	//center image

private:
	QGraphicsTextItem mObjectName; // on top of this QGraphicsItemGroup, show the element object name
	QGraphicsSvgItem mToken; // center token

	QList<Token*> mTokens;

	//share QSvgRenderer
	static QSvgRenderer token;
	//static QSvgRenderer multiToken;
};

#endif // GELEMENT_H
